package com.steven.im.ui.activity;

import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.flyco.tablayout.SlidingTabLayout;
import com.steven.im.R;
import com.steven.im.adapter.PagerAdapter;
import com.steven.im.base.BaseActivity;
import com.steven.im.entity.AccountEntity;
import com.steven.im.entity.BaseEntity;
import com.steven.im.net.MyCallback;
import com.steven.im.net.Task;
import com.steven.im.ui.fragment.transfragment.IncomeDetailsFragment;
import com.steven.im.ui.fragment.transfragment.SpendDetailFragment;
import com.steven.im.utils.GsonUtils;
import com.steven.im.utils.TitleBuilder;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import retrofit2.Response;

/**
 * Created by Steven on 2019/1/11.
 */
public class TransDetailsActivity extends BaseActivity {

    private List<Fragment> mFragments = new ArrayList<>();
    private final String[] mTitles = {"支出明细", "收入明细"};
    @BindView(R.id.stl)
    SlidingTabLayout stl;
    @BindView(R.id.vp)
    ViewPager vp;

    @BindView(R.id.tv_xingyun)
    TextView tvXingyun;
    @BindView(R.id.tv_zengsong)
    TextView tvZengsong;
    @BindView(R.id.tv_dikou)
    TextView tvDikou;

    @Override
    public void setListen() {

    }

    @Override
    public void setTitleBarColor() {
        new TitleBuilder(this).setTitleText("交易明细")
                .setLeftIcoListening(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        finish();
                    }
                });
    }

    @Override
    public int intiLayout() {
        return R.layout.activity_transdetails;
    }

    @Override
    public void initView() {
        mFragments.add(new SpendDetailFragment());
        mFragments.add(new IncomeDetailsFragment());
        vp.setAdapter(new PagerAdapter(getSupportFragmentManager(), mFragments, mTitles));
        stl.setViewPager(vp);
    }

    @Override
    public void initData() {
        //获取个人账户
        Task.getApiService().getMyAccount().enqueue(new MyCallback<BaseEntity>(this) {
            @Override
            public void onSuccess(Response<BaseEntity> response) {
                try {
                    if ("0".equals(response.body().getCode())) {
                        //获取我的账户信息成功
                        AccountEntity accountEntity = GsonUtils.parseJSON(response.body().getResult().toString(),
                                AccountEntity.class);
                        if (accountEntity != null) {
                            //刷新界面
                            //账户余额
                            tvXingyun.setText(accountEntity.getBiddingCurrency());
                            tvZengsong.setText(accountEntity.getGivingCurrency());
                            tvDikou.setText(accountEntity.getShoppingCurrency());
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Throwable t) {
            }
        });

    }

}
